
using System.Data.Common;

namespace Mistral.Data
{
	class DbSource
	{
		private DbProviderFactory _dbProviderFactory;

		private string _connectionString;
		private DbConnection _dbConnection;

		public DbSource( DbProviderFactory dbProviderFactory, string connectionString )
		{
			_dbProviderFactory = dbProviderFactory;
			_connectionString = connectionString;
		}

		public DbProviderFactory ProviderFactory
		{
			get { return _dbProviderFactory; }
		}

		public DbConnection GetConnection( )
		{
			if( _dbConnection == null )
			{
				_dbConnection = _dbProviderFactory.CreateConnection();
				_dbConnection.ConnectionString = _connectionString;			
			}
			return _dbConnection;
		}

		public DbDataAdapter CreateAdapter( )
		{
			return _dbProviderFactory.CreateDataAdapter();
		}
	}
}